/*
 * Copyright© 2003-2019 浙江汇信科技有限公司, All Rights Reserved. 
 */
package com.icinfo.cloud.provider.punish.helpmanage.controller;

import com.icinfo.cloud.common.core.page.PageResponse;
import com.icinfo.cloud.provider.punish.helpmanage.dto.HelpTypeManageDelDto;
import com.icinfo.cloud.provider.punish.helpmanage.dto.HelpTypeManageDto;
import com.icinfo.cloud.provider.punish.helpmanage.dto.HelpTypeManagePageRequest;
import com.icinfo.cloud.provider.punish.helpmanage.service.IHelpTypeManageService;
import com.icinfo.cloud.provider.punish.helpmanage.vo.HelpTypeManageVo;
import com.icinfo.framework.common.web.Result;
import com.icinfo.framework.core.web.BaseController;
import org.slf4j.Logger;
import org.slf4j.LoggerFactory;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.validation.annotation.Validated;
import org.springframework.web.bind.annotation.*;

import java.util.List;

/**
 * 描述:  help_type_manage 对应的Controller类.<br>
 *
 * @author framework generator
 * @date 2022年12月11日
 */
@RestController
@RequestMapping("/punish/helpTypeManage")
public class HelpTypeManageController extends BaseController {
    /**
     * 日志记录器
     */
    private static final Logger logger = LoggerFactory.getLogger(HelpTypeManageController.class);

    @Autowired
    private IHelpTypeManageService helpTypeManageService;
    /**
     * 【V1.10.0】描述：获取帮助类型分页列表
     *
     * @param pageRequest 页面请求
     * @return {@link Result <PageResponse< HelpTypeManageVo>> }
     * @author wuzhihui
     * @date 2022/12/06
     */
    @PostMapping(value = "/getHelpTypePageList")
    @CrossOrigin
    public Result<PageResponse<HelpTypeManageVo>> getHelpTypePageList(@RequestBody @Validated HelpTypeManagePageRequest pageRequest) {
        try {
            List<HelpTypeManageVo> voList= helpTypeManageService.getPageList(pageRequest);
            return Result.success(new PageResponse<>(voList));
        } catch (Exception e) {
            return Result.error(e.getMessage());
        }
    }
    /**
     * 【V1.10.0】描述：获取帮助类型分页列表
     *
     * @return {@link Result <PageResponse< HelpTypeManageVo>> }
     * @author wuzhihui
     * @date 2022/12/06
     */
    @CrossOrigin
    @PostMapping(value = "/getHelpTypeList")
    public Result<List<HelpTypeManageVo>> getHelpTypeList() {
        try {
            List<HelpTypeManageVo> voList= helpTypeManageService.getList();
            return Result.success(voList);
        } catch (Exception e) {
            return Result.error(e.getMessage());
        }
    }
    /**
     * 【V1.10.0】描述：保存/修改 帮助类型
     *
     * @param dto
     * @return {@link Result<String>}
     * @author wuzhihui
     * @date 2022/2/17
     */
    @CrossOrigin
    @PostMapping("/addOrUpdate")
    public Result<String> addOrUpdate(@RequestBody HelpTypeManageDto dto) {
        int count = helpTypeManageService.addOrUpdate(dto);
        return count >0 ? Result.success("保存成功"):Result.success("保存失败");
    }
    /**
     * 【V1.10.0】描述：保存/修改 帮助类型
     *
     * @param id
     * @return {@link Result<String>}
     * @author wuzhihui
     * @date 2022/12/13
     */
    @CrossOrigin
    @GetMapping("/getHelpTypeManageInfo")
    public Result<HelpTypeManageVo> getHelpTypeManageInfo(@RequestParam String id) {
        HelpTypeManageVo result = helpTypeManageService.getHelpTypeManageInfo(id);
        return Result.success(result);
    }
    /**
     * 【V1.10.0】描述：删除帮扶类型
     *
     * @param dto
     * @return {@link Result<String>}
     * @author wuzhihui
     * @date 2022/12/06
     */
    @CrossOrigin
    @PostMapping("/delete")
    public Result<String> delete(@RequestBody @Validated HelpTypeManageDelDto dto) {
        int count = helpTypeManageService.delete(dto);
        return count > 0 ? Result.success("删除成功") : Result.error("删除失败");
    }
}